<?php

    include("includes/db-config.php");
    $idSim = $_POST['idSim'];
    $file = $_POST['file'];
    $ket = $_POST['ket'];
    $idRole = $_POST['idRole'];
	
    switch($_GET['act']){
        case 1 :
                $sqlSim = "SELECT folder FROM tb_sim WHERE id_sim = '".$idSim."'";
                $querySim = mysql_query($sqlSim);
                $folder = mysql_fetch_array($querySim);
                $folder = $folder[folder]."/";
                $filePath = str_replace($folder,'',$file);
                $sqlFile = "INSERT INTO tb_file 
                                	(id_sim,file_path,file_note)
               	                    VALUES('".$idSim."','".$filePath."','".$ket."')";
                $queryFile = mysql_query($sqlFile);
                if($queryFile){
?>
                    <tr>
                        <td><?php echo $filePath;?></td>
                        <td><?php echo $ket;?></td>
                        <td><a href="#"><i class="icon-remove"></i></a></td>
                    </tr>
<?php
                }
                break;
        case 2 :     
                $sqlFile = "SELECT * FROM tb_file WHERE id_sim = '".$idSim."'";
                $queryFile = mysql_query($sqlFile);
                while($barisFile = mysql_fetch_array($queryFile)){
?>
                    <tr>
                        <td><?php echo $barisFile[file_path];?></td>
                        <td><?php echo $barisFile[file_note];?></td>
                        <td><a href="#"><i class="icon-remove"></i></a></td>
                    </tr>
<?php
                }
                break;
        case 3 :     
                $sqlFile = "SELECT b.id_role, a.id_file, a.file_note, c.name_sim FROM tb_file a
                            LEFT JOIN tb_role_access b
                            ON b.id_file = a.id_file AND id_role='".$idRole."'
                            LEFT JOIN tb_sim c
                            ON c.id_sim = a.id_sim";
                if(isset($idSim)){
                    $sqlFile .= " WHERE a.id_sim = '".$idSim."'";
                }
                $sqlFile .= " ORDER BY c.name_sim ASC";
                $queryFile = mysql_query($sqlFile);
                while($barisFile = mysql_fetch_array($queryFile)){
                    if($barisFile[id_role]==''){
                        $disp = "opacity:0.4;";
                        $checkStat = "";
                    }else{
                        $disp = "opacity:1;";
                        $checkStat = "checked='checked'";
                    }
?>
                    <tr style='cursor: pointer; <?php echo $disp;?>' class="aktif">
                        <td>
                            <input type='hidden' class='aktif-id' value='<?php echo $barisFile['id_file'];?>' />
                            <input type='checkbox' name='aktif-real' class='aktif-hid' style='display:none;' <?php echo $checkStat;?> />
                            <a href="#" class='icon-check'></a>
                        </td>
                        <td><?php echo $barisFile[file_note];?></td>
                        <td><?php echo $barisFile[name_sim];?></td>
                    </tr>
<?php
                }
                break;
        case 4 :   
                $sqlPengadaan = "INSERT INTO pengadaan_lain(id_renja, tgl_input, id_kategori, nama_barang, satuan, jumlah, harga_satuan, subtotal, sumber_referensi, spek_teknis) VALUES('".$idRenja."', '".$date."', '".$kategori."', '".$barang."', '".$satuan."', '".$qty."', '".$hSatuan."', '".$sub."', '".$sRef."', '".$sTek."')";
                echo $sqlPengadaan;
                $queryPengadaan = mysql_query($sqlPengadaan);
                if($queryPengadaan){
                    echo "sukses";
                }
                break;
    }

?>